<:!:/>

@file s.editcollection.html
@author Alejandro Dario Simi
@date $Date: 2013-05-24 23:14:00 +0000 (Fri, 24 May 2013) $

$Id: s.editcollection.html 66 2013-05-24 23:14:00Z daemonraco@gmail.com $
$URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/themes/default/templates/simplecontainer/s.editcollection.html $

<::/><script type="text/javascript">
	var	title = "Edit <:VAR:/>EDIT-WHAT<::/> collection: '<:VAR:/>EDIT-NAME<::/>'";
	var	CURRENT_LEVEL = <:VAR:/>COLLECTION-LEVEL<::/>;

	function CollectionChanged(level) {
		RemoveFromLevel(level+1);
		RequestLevel(level+1);
	}
	function RemoveFromLevel(level) {
		for(i=level; i<CURRENT_LEVEL; i++) {
			$("#COL_LIST_LVL"+i).remove();
		}
		CURRENT_LEVEL = level;
	}
	function RequestLevel(level) {
		var	preLevel	= level - 1;
		var	parent		= $("#COL_SELECTOR_LVL"+preLevel).val();		
		
		if(parent) {
			jQuery.get("service.php?xml&action=<:VAR:/>WC_SERVICE_COLLECTIONS<::/>&group=<:VAR:/>GROUP-ID<::/>&collection=" + parent,
					function(data){
				var	xml = $($.parseXML(data));
				
				$("#WARNING").attr("class", "WarningMessage");
				
				if(xml.find("wc-success").length) {
					if(xml.find("wc-result>collection").length > 0) {
						var	html	= "";
						
						html+='<tr id="COL_LIST_LVL'+level+'"><td><select id="COL_SELECTOR_LVL'+level+'" onchange="CollectionChanged('+level+');">';
						html+='<option value="" selected="selected"></option>';
						xml.find("wc-result>collection").each(function(){
							var	id		= $(this).find("id").text();
							var	name		= $(this).find("name").text();
							html+='<option value="'+id+'">'+name+'</option>';
						});
						html+='</select></td></tr>';
						
						$("#COLLECTION_SELECTORS").append(html);
	
						CURRENT_LEVEL = level + 1;
					}

					wcSimpleContainer.reposition();
				} else if(xml.find("wc-failed").length) {
					var	error = "";
					if(xml.find("wc-error>wc-code").length) {
						error = "[" + xml.find("wc-error>wc-code").text() + "] ";
					}
					error = error + xml.find("wc-error>wc-message").text();

					alert("Failed: " + error);
				}
			
				setTimeout("$('#WARNING').text('');", 2000);
			});
		}
	}
	function SendCollection() {
		var	level	= CURRENT_LEVEL - 1;
		var	id	= $("#COL_SELECTOR_LVL"+level).val();
		if(!id && level > 0) {
			level--;
			id = $("#COL_SELECTOR_LVL"+level).val();
		}
		
		if(!id) {
			id = 0;
		}

		jQuery.post("service.php?xml&action=<:VAR:/>WC_SERVICE_COLLECTIONS<::/>&group=<:VAR:/>GROUP-ID<::/>&<:VAR:/>EDIT-WHAT<::/>=<:VAR:/>EDIT-ID<::/>", {
			"COLLECTION": id
		}, function(data){
			var	xml = $($.parseXML(data));
			
			$("#WARNING").attr("class", "WarningMessage");
			
			if(xml.find("wc-success").length) {
				wcSimpleContainer.close();
			} else if(xml.find("wc-failed").length) {
				var	error = "";
				if(xml.find("wc-error>wc-code").length) {
					error = "[" + xml.find("wc-error>wc-code").text() + "] ";
				}
				error = error + xml.find("wc-error>wc-message").text();

				alert("Failed: " + error);
			}
		
			setTimeout("$('#WARNING').text('');", 2000);
		});
	}

	wcSimpleContainer.whenOpened(function(window){
		RequestLevel(CURRENT_LEVEL);
		window.title(title);
		//window.height(300);
		//window.width(800);
		wcSimpleContainer.reposition();
	});
</script>

<form id="EditForm" action="#" method="get" onSubmit="SendCollection();return false;">
	<table><tr>
		<td class="Label"><label for="GROUP">Collection:</label></td>
		<td class="Value"><table id="COLLECTION_SELECTORS">
			<:OVER:list=COLLECTION-SELECTORS:/><tr id="COL_LIST_LVL<:VAR:/>level<::/>"><td><select id="COL_SELECTOR_LVL<:VAR:/>level<::/>" onchange="CollectionChanged(<:VAR:/>level<::/>);">
				<option value=""<:ISSET:!:var=none-selected:/> selected="selected"<::/>><:IF:var=EDIT-WHAT:value=comic:/>&lt;none&gt;<::/><:IF:var=EDIT-WHAT:value=collection:/>&lt;top&gt;<::/></option>
				<:OVER:list=collections:/><option value="<:VAR:/>id<::/>"<:ISSET:var=selected:/> selected="selected"<::/>><:VAR:/>name<::/></option>
				<::/>
			</select></td></tr>
			<::/>
		</table></td>
	</tr><tr>
		<td colspan="2" class="Buttons">
			<input type="submit" value="Set"/>
			<input type="submit" value="Cancel" onclick="wcSimpleContainer.close();return false;"/>
		</td>
	</tr><tr>
		<td colspan="2" id="WARNING" class="WarningMessage"></td>
	</tr></table>
</form>
